package com.huawei.java.alogrithm;

import com.huawei.java.model.Demand;

import java.util.List;
import java.util.Map;

public class PreDistribution {
    /**
     *  按总需求排序 去除后面5%的需求进行权重排序
     *
     * @param demands 需求
     */
    public void handleDemands(List<Demand> demands) {
        int ceil = (int) Math.ceil(demands.size() * 0.95);
        demands.sort((oneDemand, anotherDemand) -> {
            Map<String, Integer> oneDemandMap = oneDemand.getDemandMap();
            int oneTotalDemand = oneDemandMap.values().stream().mapToInt(Integer::intValue).sum();
            Map<String, Integer> anotherDemandMap = anotherDemand.getDemandMap();
            int antherTotalDemand = anotherDemandMap.values().stream().mapToInt(Integer::intValue).sum();
            return oneTotalDemand - antherTotalDemand;
        });
        demands.stream().skip(ceil).forEach(demand -> demand.setNinetyFiveThreshold(true));
        //System.out.println(demands);
    }
}
